package com.pesilo.mvc.view.component.mediator
{
	import com.pesilo.mvc.controller.ApplicationFacade;
	import com.pesilo.mvc.model.vo.BackgroundImageVO;
	import com.pesilo.mvc.view.component.module.BackgroundContainerComponent;
	import com.pesilo.mvc.view.component.module.backgroundModule.BackgroundComponent;
	
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;

	public class BackgroundContainerMediator extends Mediator implements IMediator
	{
		public static const NAME:String="BackgroundConainerMediator";
		public function BackgroundContainerMediator(viewComponent:Object)
		{
			super(NAME,viewComponent);
		}
		
		override public function onRegister():void{
			
		}
		
		override public function listNotificationInterests():Array{
			return[
				ApplicationFacade.SHOW_BACKGROUND_EVENT
			]
		}
		
		override public function handleNotification(notification:INotification):void{
			var data:Object=notification.getBody();
			
			switch(notification.getName()){
				case ApplicationFacade.SHOW_BACKGROUND_EVENT:
					if(!view.bgCmp){
						view.bgCmp=new BackgroundComponent(data as BackgroundImageVO);
					}
					view.addChild(view.bgCmp);
					break;
			}
		}
		
		protected function get view():BackgroundContainerComponent{
			return viewComponent as BackgroundContainerComponent;
		}
	}
}